<template>
	<el-container>
	  <el-header class="header3">
		  <el-date-picker
		        v-model="value1"
		        type="date"
		        placeholder="选择日期">
		      </el-date-picker>
			  <el-button type="primary" @click="searchfinance">搜索</el-button>
			  <el-dialog
			    title="查找"
			    :visible.sync="istrue"
			    width="40%"
			    :before-close="handleClose">
			    <el-table
			        :data="searchfindata"
			        border
			       
			    				>
			    	<el-table-column
			    			label="编号"
			    			type="index"
			    			width="70">
			    		</el-table-column>
			    		<el-table-column
			    			prop="username"
			    			label="核对人"
			    			width="100">
			    		</el-table-column>
			    		<el-table-column
			    			prop="verifydata"
			    			label="核对日期"
			    			width="200">
			    		</el-table-column>
			    		<el-table-column
			    			prop="totalprice"
			    			label="商品总价(元)"
			    			>
			    		</el-table-column>	  
			      </el-table>
			  				<span slot="footer" class="dialog-footer">
			  					<el-button type="primary" @click="istrue = false">确 定</el-button>
			  				</span>
			  </el-dialog>
	  </el-header>
	  <el-main class="main3">
				<el-table
				    :data="alfindata"
				    border
				    style="width: 45%;margin-left: 300px;"
								>
					<el-table-column
							label="编号"
							type="index"
							width="70">
						</el-table-column>
						<el-table-column
							prop="username"
							label="核对人"
							width="100">
						</el-table-column>
						<el-table-column
							prop="verifydata"
							label="核对日期"
							width="200">
						</el-table-column>
						<el-table-column
							prop="totalprice"
							label="商品总价(元)"
							>
						</el-table-column>	  
				  </el-table>
				  <el-pagination
				  	background
				  	@size-change="size_change"
				  	@current-change="current_change"
				  	:current-page=pageNum 
				  	:page-size = 5
				  	layout="prev, pager, next"
				  	:total= "total">
				  </el-pagination>
		  
	  </el-main>
	  
	</el-container>
</template>

<script>
	var padaDate = function(value){
	     return value<10 ? '0'+value : value;
	  };
	export default {
		name: 'finance2',
		data() {
			return {
				value1: '',
				date: '',
				alfindata:[],
				searchfindata:[],
				pageNum: 1,
				total: 0,
				istrue: false,
			}
		},
		mounted() {
			this.display()
		},
		methods: {
			display() {
				var url = "http://localhost:8848/alfin/display?pagenum="+this.pageNum;
				
				this.$axios.get(url)
				.then( (resp) => {
					var u = resp.data;
					
					this.alfindata = u.list;
					this.pageNum = u.pageNum;
					this.total = u.total;
					console.log(this.alfindata);
				})
				.catch( (err) => {
					console.log("error=", err);
				})
			},
			searchfinance() {
				this.istrue = true;
				var year = this.value1.getFullYear();
				var month = padaDate(this.value1.getMonth()+1);
				var day = padaDate(this.value1.getDate());
				this.date = year+'-'+month+'-'+day;
				// console.log(this.date);
				
				var url = "http://localhost:8848/alfin/search?verifydata="+this.date;
				console.log(url);
				
				this.$axios.get(url)
				.then( (resp) => {
					var u = resp.data;
					
					this.searchfindata = u;
				})
				.catch( (err) => {
					console.log("error=", err);
				})
			},
			size_change(newSize){
			    this.pageSize = newSize
							   // this.inventorydate.push(this.pagelist);
							   console.log(newSize);
			},
			//监听 页码值 改变的事件
			current_change(newPage){
			    this.pageNum = newPage
			    //this.comeindata.push(this.pagelist);
			    console.log(newPage);
				this.searchfinance();
			},
		},
		
		
	}
</script>

<style>
</style>
